import 'package:ft_reader/beans/book_bean.dart';
import 'package:ft_reader/blocs/base_bloc.dart';
import 'package:rxdart/rxdart.dart';
import 'package:rxdart/subjects.dart';

class BookShelfBloc extends BaseBloc {

  final _bookShelfFetcher = PublishSubject<List<BookBean>>();

  //监听
  Observable<List<BookBean>> get bookShelf => _bookShelfFetcher.stream;


  void fetcherBooks(books) async {
    if (!_bookShelfFetcher.isClosed) {
      _bookShelfFetcher.sink.add(books);
    }
  }

  @override
  void dispose() {
    super.dispose();
    _bookShelfFetcher.close();
  }



  BookBean updateBook (int bookId) {
    BookBean _book = BookBean();
    netApi.fetchBookInfoData(bookId).then((_bookInfo) {
      if (_bookInfo != null) {
        _book.id = _bookInfo.data.id;
        _book.name = _bookInfo.data.name;
        _book.desc = _bookInfo.data.desc;
        _book.img = _bookInfo.data.img;
        _book.author = _bookInfo.data.author;
        _book.updateTime = _bookInfo.data.lastTime;
        _book.lastChapter = _bookInfo.data.lastChapter;
        _book.lastChapterId = _bookInfo.data.lastChapterId.toString();
        _book.cname = _bookInfo.data.cName.toString();
        _book.bookStatus = _bookInfo.data.bookStatus.toString();
      }
    });
    return _book;
  }
}